package com.lj.demo.cmsservice.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lj.demo.cmsservice.entity.CrmBanner;
import com.lj.demo.cmsservice.service.CrmBannerService;
import com.lj.demo.commonutils.R;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;

/**
 * <p>
 * 首页banner表 管理员控制器
 * </p>
 *
 * @author liujiang
 * @since 2020-12-21
 */
@RestController
@RequestMapping("/cmsservice/banner")
//@CrossOrigin
public class CrmBannerAdminController {

    @Autowired
    private CrmBannerService crmBannerService;

    @ApiOperation(value = "获取banner分页列表")
    @GetMapping("index/{page}/{limit}")
    public R index(@PathVariable Long page,@PathVariable Long limit){
        Page<CrmBanner> pageParam = new Page<>(page,limit);
        crmBannerService.page(pageParam,null);
        return R.ok().data("items",pageParam.getRecords()).data("total",pageParam.getTotal());
    }

    @ApiOperation(value = "根据id获取幻灯片")
    @GetMapping("getBanner/{id}")
    public R getBanner(@PathVariable String id){
        CrmBanner banner = crmBannerService.getBannerById(id);
        return R.ok().data("items",banner);
    }

    @ApiOperation(value = "添加幻灯片")
    @PostMapping("addBanner")
    public R addBanner(@RequestBody CrmBanner crmBanner){
        crmBannerService.saveBanner(crmBanner);
        return R.ok();
    }

    @ApiOperation(value = "修改幻灯片")
    @PostMapping("updateBanner")
    public R updateBanner(@RequestBody CrmBanner crmBanner){
        crmBannerService.updateBannerById(crmBanner);
        return R.ok();
    }
    @ApiOperation(value = "根据id删除幻灯片")
    @DeleteMapping("deleteBanner/{id}")
    public R deleteBanner(@PathVariable String id){
        crmBannerService.removeBannerById(id);
        return R.ok();
    }

}

